package com.keyue.isolate.context;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.keyue.common.constant.Constant;
import lombok.Data;

import java.util.List;

@Data
public class DataIsolateValue {
    private List<String> carrierCodes;
    private List<String> customerCodes;
    private List<String> contractBodyCodes;
    private List<String> sourcePlatformCodes;
    private List<String> warehouseCodes;
    private List<String> transportTypeCodes;
    private List<String> subTransportTypeCodes;
    private List<String> companyCodes;
    private List<String> fromCityCodes;

    @JsonIgnore
    @JSONField(serialize = false)
    public boolean isSelectAll() {
        return isSelectAll(carrierCodes) && isSelectAll(customerCodes) && isSelectAll(contractBodyCodes) &&
                isSelectAll(sourcePlatformCodes) && isSelectAll(warehouseCodes) && isSelectAll(transportTypeCodes) &&
                isSelectAll(subTransportTypeCodes) && isSelectAll(companyCodes);
    }

    @JsonIgnore
    @JSONField(serialize = false)
    private boolean isSelectAll(List<String> codes) {
        if (CollectionUtils.isEmpty(codes)) {
            return true;
        }

        return codes.stream().anyMatch(Constant.ALL::equalsIgnoreCase);
    }
}
